<template>
    <div id="app">
        <router-view :key="routerKey"></router-view>
    </div>
</template>

<script>
    import "./assets/css/base.css"
    import "./assets/css/index.css"
    import "./assets/css/login.css"
    import "./assets/css/index_before.css"
    var _this;
    export default {
        name: 'App',
        data() {
            return {
                name: "app",
                loginInfo: {},
                cookieRenewal: false,
                version: this.$cookies.get("version"),
                webVersion: 0,
                isLogin: undefined,
                products: []
            }
        },
        computed: {

            routerKey() {
                return new Date().getTime()/1000
            }
        },
        beforeCreate: function() {
            _this = this;
        },
        created: function() {
            this.common._setVue(this);
            var loginInfo = this.$cookies.get('loginInfo');
            if (loginInfo != undefined) {
                this.loginInfo = loginInfo;
            }

            this.common.getHttpHeaders = function() {
                var token = _this.$cookies.get('token');
                _this.cookieRenewal = (token != undefined);
                token = token == undefined ? "" : token;
                var h = {
                    token: token,
                    version: _this.api.version
                };
                return h;
            };
            this.common.xujiqi = _this.getNewToken;
        },
        mounted: function() {
        },
        methods: {
            getNewToken: function(url, data) {
                if (url == this.api.getNewToken || url == this.api.verifyCode || url == this.api.login) {
                    return;
                }
                var _this = this;
                this.common.postNotLoading(this.api.getNewToken, {}, function(res) {
                    if (res.resultMap == "false") {
                        _this.$message.warning("您的账号已在其它电脑登录！！！");
                        setTimeout(function() {
                            _this.common.toPage('/login', true);
                        }, 2000);
                        return;
                    }
                    if (res.resultMap == _this.$cookies.get('token') || String.isEmptyOrNUll(res
                            .resultMap)) {
                        return;
                    }
                    _this.$cookies.set("token", res.resultMap, _this.api.config.tokenTime)
                }, function(err) {
                    _this.$message.error(err.resultMsg);
                    _this.$cookies.set("token", undefined);
                    _this.common.toPage("/login");
                });

            }
        }
    }
</script>

<style>
</style>
